﻿using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace news.admin.cyt369.com.services.Services
{
    public class DocTypeService : admin.cyt369.com.services.ORM.BaseService<DocTypeService>
    {
        ///// <summary>
        ///// 获取栏目树
        ///// </summary>
        ///// <param name="parentId"></param>
        ///// <param name="not_id"></param>
        ///// <returns></returns>
        //public IEnumerable<news.admin.cyt369.com.services.Models.DocumentType> GetDocumentTypes(long parentId = 0, int? not_id = null)
        //{
        //    var db = this.Ctx;
        //    IQueryable<news.admin.cyt369.com.services.Models.DocumentType> menus = null;
        //    if (not_id.HasValue) 
        //    {
        //        menus = from o in db.Set<news.admin.cyt369.com.services.Models.DocumentType>()
        //                where o.ParentID == parentId && o.Deleted == false && o.Id != not_id.Value
        //                select o;
        //    }
        //    else {
        //        menus = from o in db.Set<news.admin.cyt369.com.services.Models.DocumentType>()
        //                where o.ParentID == parentId && o.Deleted == false
        //                select o;
        //    }

        //    foreach (var m in menus)
        //    {
        //        foreach (var sm in GetDocumentTypes(m.Id, not_id))
        //        {
        //            m.SubTypes.Add(sm);
        //        }
        //    }

        //    return menus.OrderBy(c => c.Sequence);
        //}

        ///// <summary>
        ///// 一级栏目
        ///// </summary>
        ///// <param name="parentId"></param>
        ///// <param name="not_id"></param>
        ///// <returns></returns>
        //public IEnumerable<news.admin.cyt369.com.services.Models.DocumentType> GetRootDocumentType()
        //{
        //    return this.Get<news.admin.cyt369.com.services.Models.DocumentType>(c=>c.ParentID == 0).OrderBy(c => c.Sequence);
        //}

        public news.admin.cyt369.com.services.Models.UserDocCategory GetDocumentTypeByID(long id)
        {
            return base.GetOne<news.admin.cyt369.com.services.Models.UserDocCategory>(c => c.Id == id);
        }

        //public bool DeleteDocumentType(long id)
        //{
        //    return base.Delete<news.admin.cyt369.com.services.Models.DocumentType>(c=>c.Id == id, delegate(IQueryable<news.admin.cyt369.com.services.Models.DocumentType> types) {
        //        foreach (var t in types)
        //        {
        //            t.Deleted = true;
        //        }
        //    });
        //}

        //public bool SaveDocumentType(news.admin.cyt369.com.services.Models.DocumentType category)
        //{
        //    using (var db = this.Ctx)
        //    {
        //        //var level = 0;
        //        //var item = (from o in db.Set<news.admin.cyt369.com.services.Models.DocumentType>()
        //        //           where o.Id == category.Id
        //        //           select o).FirstOrDefault();

        //        //if(category.ParentID > 0)
        //        //{
        //        //    var parent = (from o in db.Set<news.admin.cyt369.com.services.Models.DocumentType>()
        //        //                  where o.Id == category.ParentID
        //        //                  select o).FirstOrDefault();
        //        //    level = parent.Level + 1;
        //        //}

        //        //category.Level = level;

        //        //if (item == null)
        //        //{
        //        //    db.Set<news.admin.cyt369.com.services.Models.DocumentType>().Add(category);
        //        //}
        //        //else
        //        //{
        //        //    item.ParentID = category.ParentID;
        //        //    item.Name = category.Name;
        //        //    item.Description = category.Description;
        //        //    item.URL = category.URL;
        //        //    item.Sequence = category.Sequence;
        //        //    item.IconClassName = category.IconClassName;
        //        //    item.Level = category.Level;
        //        //}

        //        //db.SaveChanges();

        //        return true;
        //    }
        //}
        //#endregion
    }
}
